M8b: $formatInteger + $parseInteger (XPath integer pictures)#27
Merged
Conversation
New functions/formatinteger.lua: analyse_integer_picture + decimal-digit-pattern format/parse (Unicode digit families, regular+irregular grouping, ordinal suffix with the teen exception, D3131 mixed-group). Registers $formatInteger <n-s:s> / $parseInteger <s-s:n>; roman/letters/words branches follow. Hoists codepoint/from_codepoint into H (shared with formatnumber, and M8c next). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
format_decimal used tostring(value) which yields scientific notation for large integer-valued floats (1000000000000000 -> "1e+15"). Use H.num_to_str, which formats integer-valued numbers via %d. Matches the oracle. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
decimalToRoman/romanToDecimal (subtractive) and bijective base-26 decimalToLetters/lettersToDecimal, both directions; D3130 for unsupported sequence tokens. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ections numberToWords recursive engine (magnitudes to trillion, clamped; and/comma joins; ordinal mutations) + wordsToNumber (wordValues table + segment-accumulate) for w/W/Ww. Completes $formatInteger/$parseInteger. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…1, zero regressions Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
words_to_number crashed (nil < 100) on unrecognized tokens; jsonata's wordsToNumber maps them to undefined, whose lenient coercion yields NaN. Mirror that (nil routes to the multiply branch, * NaN). Matches the oracle (null). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$formatInteger(number, picture)+$parseInteger(string, picture)— a faithful Lua port of jsonata-js v2.2.1's XPath/XSLTfn:format-integerpicture machinery, in a new modulesrc/jsonata/functions/formatinteger.lua. Both directions for all four format families:١, fullwidth0, …), regular + irregular grouping, ordinal;osuffixes (st/nd/rd/th with the 11–13th teen exception), D3131 mixed-family.I/i), letters (a/A, bijective base-26), words (w/W/Ww, cardinal + ordinal, magnitudes clamped to trillion).analyse_integer_picture+ the four converter pairs; internals exported (_internal) for M8c ($formatDateTime/$parseDateTime) reuse.codepoint/from_codepointintoH(shared with$formatNumber). D3130/D3131 errors.Suite impact
function-formatInteger2 → 65/65;function-parseInteger1 → 61/61.Test Plan
spec/formatinteger_spec.luacovers every category both directions + large ints, families, ordinal/teen edges, D3130/D3131, NaN-on-garbage.🤖 Generated with Claude Code